# -*- coding: utf-8 -*-
'''
    :file: settings.py
    :author: -Farmer
    :url: https://blog.farmer233.top
    :date: 2021/02/10 16:16:52
'''

import os
import sys

from sqlalchemy.sql.expression import true

basedir = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))

# SQLite URI compatible
WIN = sys.platform.startswith('win')
if WIN:
    prefix = 'sqlite:///'
else:
    prefix = 'sqlite:////'

# 基本配置
class BaseConfig(object):
    # 鉴权加密密钥（cookie）
    SECRET_KEY = os.getenv('SECRET_KEY', 'dev key')
    # 密码重置密钥（找回密码）
    RESET_SECRET_KEY = os.getenv("RESET_SECRET_KEY", "reset dev key")
    # 网盘文件的根目录
    UPLOAD_FOLDER = os.getenv('FILE_SAVE_PATH', os.path.join(basedir, "TestDir"))
    # ORM框架配置
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    # 系统标识
    MCLOUD_MAIL_SUBJECT_PREFIX = os.getenv("MCLOUD_MAIL_SUBJECT_PREFIX", "[MCloud]")
    # 邮箱服务配置
    MAIL_SERVER = os.getenv('MAIL_SERVER')
    MAIL_PORT = 465
    MAIL_USE_SSL = True
    MAIL_USERNAME = os.getenv('MAIL_USERNAME')
    MAIL_PASSWORD = os.getenv('MAIL_PASSWORD')
    MAIL_DEFAULT_SENDER = ('MCloud Admin', MAIL_USERNAME)
    # redis配置
    REDIS_HOST = os.getenv("REDIS_HOST", "Host")
    REDIS_PORT = os.getenv("REDIS_PORT", 6379)
    REDIS_PASSWD = os.getenv("REDIS_PASSWD", "password")
    REDIS_DB = os.getenv("REDIS_DB", 0)
    REDIS_EXPIRE = os.getenv("REDIS_EXPIRE", 3600) # redis 过期时间3600秒

    # 定时器配置
    SCHEDULER_API_ENABLED = True
    # DDNS配置
    DDNS_STATUS = False
    DDNS_DOMAIN_NAME_IP = ''
    DDNS_LOCAL_IP = ''

# 开发环境配置
class DevelopmentConfig(BaseConfig):
    # 开发环境使用sqlite作为开发数据库
    SQLALCHEMY_DATABASE_URI = prefix + os.path.join(basedir, 'data-dev.db')

# 测试配置
class TestingConfig(BaseConfig):
    TESTING = True
    WTF_CSRF_ENABLED = False
    SQLALCHEMY_DATABASE_URI = 'sqlite:///:memory:'  # in-memory database

# 生产环境配置
class ProductionConfig(BaseConfig):
    SQLALCHEMY_DATABASE_URI = os.getenv('DATABASE_URL', prefix + os.path.join(basedir, 'data.db'))

# xport配置
config = {
    'development': DevelopmentConfig,
    'testing': TestingConfig,
    'production': ProductionConfig
}